#!/bin/bash

if [[ "$1" == "debug" ]]; then
    BUILDOPT='-g -Og'
else
    BUILDOPT='-O3'
fi

echo "run_worldmap: building C++ code"

rm -f bin/worldmap
mkdir -p bin
g++ -Wall -Werror -x c++ -std=c++11 -o bin/worldmap $BUILDOPT \
    -I./raytrace -I../../source/c \
    worldmap.cpp astro_demo_common.c ../../source/c/astronomy.c raytrace/lodepng.cpp \
    || exit $?

echo "run_worldmap: creating image"

rm -f sun_moon_map.png test/worldmap.txt
time bin/worldmap sun_moon_map.png 2022-04-09T16:05:35Z > test/worldmap.txt || exit $?
more test/worldmap.txt || exit $?
if ! diff {correct,test}/worldmap.txt; then
    echo "run_worldmap: FAIL - incorrect zenith location output."
    exit 1
fi

ls -l sun_moon_map.png || exit $?
../../generate/checksum.py sha256 worldmap.sha256 || exit $?
echo "run_worldmap: PASS"
exit 0
